s = '伟大的中国梦'

# 编码
scode_gbk = s.encode('gbk')
print(scode_gbk)

scode_utf8 = s.encode('utf-8')  # 默认utf-8
print(scode_utf8)

# 编码中的error处理
s2 = '耶و'
scode = s2.encode('gbk', errors='replace')  # 替换问号
print(scode)

scode = s2.encode('gbk', errors='ignore')  # 忽略
print(scode)

# scode = s2.encode('gbk', errors='strict')  # 报错
# print(scode)

# 解码
print(bytes.decode(scode_gbk, 'gbk'))
print(bytes.decode(scode_utf8, 'utf-8'))
print(bytes.decode(scode, 'gbk', errors='ignore'))